package com.kgc.scd.controller;

import com.kgc.scd.bean.OrderXZY;
import com.kgc.scd.contant.CommonConstant;
import com.kgc.scd.service.OrderServiceXZY;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: com.kgc.scd.controller
 * @author: HarryXzy
 * @create: 2022-06-17 09:49
 * @description: 订单物流查询接口
 **/
@RestController
public class OrderExpreController {

    @Autowired
    private OrderServiceXZY orderServiceXZY;



    @PostMapping("/searchExpByOrderId")
    public Map<String, Object> searchExpByOrderId(@RequestParam(value = "orderId") String orderId) throws Exception {
        System.out.println("------");

        HashMap<String, Object> map = new HashMap<>();
        OrderXZY expreIdByOrderId = orderServiceXZY.getExpreIdByOrderId(orderId);
        if(expreIdByOrderId == null){
            map.put("code", CommonConstant.UNIFY_RETURN_FAIL_CODE);
            map.put("msg", CommonConstant.UNIFY_RETURN_FAIL_CODE);
            map.put("data","订单号不存在");
            return map;
        }
        if(expreIdByOrderId.getOrderExpressid() == null){
            map.put("code", CommonConstant.UNIFY_RETURN_SUCCESS_CODE);
            map.put("msg", CommonConstant.UNIFY_RETURN_SUCCESS_MSG);
            map.put("data","该订单暂未发货");
            return map;
        }
        Object expressMsgByExpressId = orderServiceXZY.getExpressMsgByExpressId(expreIdByOrderId.getOrderExpressid(),expreIdByOrderId.getOrderExpresscor());
        map.put("code", CommonConstant.UNIFY_RETURN_SUCCESS_CODE);
        map.put("msg", CommonConstant.UNIFY_RETURN_SUCCESS_MSG);
        map.put("data",expressMsgByExpressId);
        return map;
    }


    @PostMapping("/sendOrder")
    public Map<String, Object> sendOrder(@RequestParam(value = "orderId") String orderId,
                                         @RequestParam(value = "expressCor") String ExpressCor,
                                         @RequestParam(value = "expressId") String ExpressId){
        HashMap<String, Object> map = new HashMap<>();
        if(orderServiceXZY.sendOrder(orderId,ExpressCor,ExpressId)){
            map.put("code", CommonConstant.UNIFY_RETURN_SUCCESS_CODE);
            map.put("msg", CommonConstant.UNIFY_RETURN_SUCCESS_MSG);
            map.put("data","");
            return map;
        }
        map.put("code", CommonConstant.UNIFY_RETURN_FAIL_CODE);
        map.put("msg", CommonConstant.UNIFY_RETURN_FAIL_MSG);
        map.put("data","");
        return map;

    }


}
